<?php
// +----------------------------------------------------------------------
// | INPHP
// | Copyright (c) 2023 https://inphp.cc All rights reserved.
// | Author: 幺月儿(https://gitee.com/lulanyin) Email: inphp@qq.com
// | 该文件的开源协议以所在项目的LICENSE文件为准，请遵守开源协议要求
// +----------------------------------------------------------------------
// | 站点列表
// +----------------------------------------------------------------------
namespace app\cms\tags;

use app\cms\model\SiteModel;
use Inphp\Core\Context;

class sites extends aTag
{
    public static function process(array $params): array
    {
        //默认不包含当前站点
        $excludeId = !empty($params["excludeId"]) ? $params["excludeId"] : null;
        if (empty($excludeId)) {
            $site = Context::get("CMS_SITE");
            $excludeId = $site ? $site["id"] : 0;
        }
        $excludeId = explode(",", $excludeId);
        $cache = self::getCache(["excludeId" => $excludeId], "site");
        if ($cache) {
            return $cache;
        }
        $list = SiteModel::getCache();
        $result = [];
        foreach ($list as $item) {
            if ($item["state"] == 1 && !in_array($item["id"], $excludeId)) {
                $result[] = $item;
            }
        }
        self::setCache(["excludeId" => $excludeId], $result, "site");
        return $result;
    }
}